<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\Config;
use think\Db;
use think\Session;


class Advertisement extends AdminBase
{   
    
    protected function initialize()
    {
    	parent::initialize();	
    }
	/*
	 * 获取广告信息
	 * @author ys
	 */
	public function index($keyword = '', $page = 1)
	{
		$map = [];
        if ($keyword) {
            $map['name'] = ['like', "%{$keyword}%"];
        }	
		$ad=db('ad',[],false)->where($map)->paginate(15, false, ['page' => $page]);
		$this->assign('keyword',$keyword);
		$this->assign('ad',$ad);
		return $this->fetch();
	}
	/*
    * 添加广告
    */
    public function  add()
    {
        return $this->fetch(); 
    }
    
    /*
     * 保存广告
     */
    
     public function save()
    {
        if ($this->request->isPost()) {
         $data            = $this->request->post();
         db('ad')->insert($data);
         return $this->success('保存成功');
        }
    }
    /*
     * 编辑广告
     */
     public function edit($id = 0)
    {
      $ad = db('ad')->where('id',$id)->find();
      $this->assign('ad',$ad);
      return $this->fetch();
    }
      /*
       * 更新广告
       */ 
      public function update($id = 0)
      {
          $data   = $this->request->post();
         $ad= db('ad')->where('id',$id)->update($data);
         return $this->success('更新成功');                
      }
    /*
     * 删除广告
     */
     public function delete($id = 0, $ids = [])
    {
         db('ad')->where('id',$id)->delete();
         return $this->success('删除成功');
    }
}
?>